package jmotioncapture.geometry2D;

import jmotioncapture.calculation.GeomCalculation;

/**
 * This class represent a line segment with <b>direction</b> which is a part of
 * a line that is bounded by <b>two distinct end points</b>.
 * 
 * @author Kenneth
 * @since 1.0.0
 * 
 */
public class Line {

	/**
	 * Starting point.
	 * 
	 * @since 1.0.0
	 */
	private Point startPoint;

	/**
	 * End point.
	 * 
	 * @since 1.0.0
	 */
	private Point endPoint;

	/**
	 * Constructs a line with specific start point and end point.<br>
	 * 
	 * @param startPoint
	 *            Starting Point.
	 * @param endPoint
	 *            End Point.
	 * @since 1.0.0
	 */
	public Line(Point startPoint, Point endPoint) {
		this.startPoint = startPoint;
		this.endPoint = endPoint;
	}

	/**
	 * Set the starting point of the line.
	 * 
	 * @param startPoint
	 *            Starting Point
	 * @since 1.0.0
	 */
	public void setStartPoint(Point startPoint) {
		this.startPoint = startPoint;
	}

	/**
	 * Set the end point of the line.
	 * 
	 * @param startPoint
	 *            Starting Point
	 * @since 1.0.0
	 */
	public void setEndPoint(Point endPoint) {
		this.endPoint = endPoint;
	}

	/**
	 * Get the starting point of the line, represented by the returned
	 * <code>Point</code>.
	 * 
	 * @since 1.0.0
	 */
	public Point getStartPoint() {
		return this.startPoint;
	}

	/**
	 * Get the end point of the line.
	 * 
	 * @since 1.0.0
	 */
	public Point getEndPoint() {
		return this.endPoint;
	}

	/**
	 * Get the slope of the line, represented by the returned
	 * <code>double</code>. <br>
	 * <li>If the result is infinity, then return NaN.</li><br>
	 * 
	 * Using {@link jmotioncapture.calculation.GeomCalculation#slope(Point, Point)} method to implement.
	 * 
	 * @return Slope in double.
	 * @since 1.0.0
	 */
	public double getSlope() {
		return GeomCalculation.slope(startPoint, endPoint);
	}

	/**
	 * Get the distance of the line, represented by the returned
	 * <code>double</code>. <br>
	 * 
	 * Using {@link jmotioncapture.calculation.GeomCalculation#distance(Point, Point)} method to implement.
	 * 
	 * @return Distance in double. (Pixel)
	 * @since 1.0.0
	 */
	public double getDistance() {
		return GeomCalculation.distance(startPoint, endPoint);
	}

	/**
	 * Get the mid-point of the line, represented by the returned
	 * <code>Point</code>. <br>
	 * 
	 * Using {@link jmotioncapture.calculation.GeomCalculation#midPoint(Point, Point)} method to implement.
	 * 
	 * @return Mid-point of the line
	 * @since 1.0.0
	 */
	public Point getMidPoint() {
		return GeomCalculation.midPoint(startPoint, endPoint);
	}

	/**
	 * Get the angle in degree of the line, represented by the returned
	 * <code>double</code>. <br>
	 * <li>12 o'clock = 0 degree.</li>
	 * <li>3 o'clock = 90 degree.</li>
	 * <li>6 o'clock = 180 degree.</li>
	 * <li>9 o'clock = 270 degree.</li>
	 * 
	 * Using {@link jmotioncapture.calculation.GeomCalculation#polarAngle(Point, Point)} method to implement.
	 * 
	 * @return polar angle of the line.
	 * @since 1.0.0
	 */
	public double getPolarAngle() {
		return GeomCalculation.polarAngle(startPoint, endPoint);
	}

}
